package model

import "ginBasic/global"

var AccessRoleModel = new(RoleAccess)

type RoleAccess struct {
	AccessId int
	RoleId   int
}

func (RoleAccess) TableName() string {
	return "role_access"
}

func (RoleAccess) GetAccessByRoleId(roleId int) []RoleAccess {
	var roleAccess []RoleAccess
	global.DB.Where("role_id=?", roleId).Find(&roleAccess)
	return roleAccess
}

func (RoleAccess) Add(roleAccess []*RoleAccess) (bool, error) {
	err := global.DB.CreateInBatches(roleAccess, len(roleAccess)).Error
	if err != nil {
		return false, err
	}
	return true, nil
}

func (RoleAccess) Delete(id int) (bool, error) {
	err := global.DB.Where("role_id=?", id).Delete(&RoleAccess{}).Error
	if err != nil {
		return false, err
	}
	return true, nil
}
